<?php
declare (strict_types = 1);

namespace app\api\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Goods extends Model
{
    /**
     * 根据类型id查询商品信息
     * @param $typeId
     * @return Goods|array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function  getTypeByGoods($typeId){
        return self::where("type_id",$typeId)->find();
    }
    public function brand(){
        return $this->belongsTo(Brand::class)->bind([
            'brand_name'=>'name'
        ]);
    }
    public function cate(){
        return $this->belongsTo(Category::class,'cate_id');
    }
    public function images(){
        return $this->hasMany(GoodsImages::class);
    }

}
